﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Feedback.Business;

namespace FeedbackWebClient
{
    /// <summary>
    /// Summary description for Feedback
    /// </summary>
    public class Feedback : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            
            if(new FeedbackLogic().Save(Longitude, Latitude, LocationName, Address, FeedbackText, CustomerEmail, MobileId, GoogleMapsId, BusinessIdentId, Hash))
            {
                
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }

        private double? Longitude
        {
            get
            {
                return GetDoubleValue("longitude");
            }
        }
        private double? Latitude
        {
            get
            {
                return GetDoubleValue("longitude");
            }
        }

        private string LocationName
        {
            get
            {
                return GetStringValue("locationname");
            }
        }
        private string Address
        {
            get
            {
                return GetStringValue("address");
            }
        }
        private string FeedbackText
        {
            get
            {
                return GetStringValue("feedbacktext");
            }
        }

        private string CustomerEmail
        {
            get
            {
                return GetStringValue("customerEmail");
            }
        }

        private string MobileId
        {
            get
            {
                return GetStringValue("mobileId");
            }
        }
        private string GoogleMapsId
        {
            get
            {
                return GetStringValue("googleMapsId");
            }
        }
        private int? BusinessIdentId
        {
            get
            {
                return GetIntergerValue("businessIdentId");
            }
        }
        private string Hash
        {
            get
            {
                return GetStringValue("hash");
            }
        }

        private double? GetDoubleValue(string key)
        {
            double d;
            if (double.TryParse(HttpContext.Current.Request.Form[key], out d))
                return d;
            return null;
        }
        private int? GetIntergerValue(string key)
        {
            int d;
            if (int.TryParse(HttpContext.Current.Request.Form[key], out d))
                return d;
            return null;
        }
        private string GetStringValue(string key)
        {
            return HttpContext.Current.Request.Form[key];
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}